<template>
  <div class="p-3">
    <input class="form-control mb-3" type="file" @change="hangleChange" />
    <c-table
      border
      height="90vh"
      class="table-sm"
      :columns="tableColumns"
      :data="tableData"
    ></c-table>
  </div>
</template>

<script>
import { excelRead } from '@vimi/utils-tool'
import { dateFormat } from '@/common/utils/common'

export default {
  components: {},
  props: {},
  data() {
    return {
      tableData: [],
      tableColumns: [{ attrs: { prop: 'A', label: '选择' } }],
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    hangleChange(e) {
      var files = e.target.files || e.dataTransfer.files

      excelRead(
        files[0],
        [
          {
            A: { k: 'index' },
            E: { t: 'd', f: v => dateFormat(v, 'yyyy/M/d') },
            F: { t: 'd', f: v => dateFormat(v, 'yyyy/M/d') },
            L: { t: 'd', f: v => dateFormat(v, 'yyyy/M/d') },
            M: { t: 'd', f: v => dateFormat(v, 'yyyy/M/d') },
          },
        ],
        [
          {
            json: true, // default is true
            start: { c: 1, r: 3 },
          },
        ]
      ).then(res => {
        // eslint-disable-next-line no-console
        console.log(res)

        if (!res || !res.SheetNames.length) return
        this.tableData = res.SheetData[res.SheetNames[0]]
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
